<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
    <%@ include file="/static/admin/jsp/include.jsp"%>
    <script type="text/javascript">
        var idarr = "${idarr}";
        var submitForm = function($dialog, $grid, $pjq) {
            if ($('form').form('validate')) {
                var obj=sy.serializeObject($('form'));
                var data = [];
                var imgsStr = "";
                for (var i = 0; i <= tuwen; i++){
                    if ($('#content'+i).length == 0) continue;
                    var content = $('#content'+i).val();
                    var img = $('#images'+i).getFileId();
                    if (!content&&!img){
                        continue;
                    }
                    var imgs = img?img:'';
                    var json = {content:content,img:imgs};
                    data.push(json);
                    if(imgsStr != ''){
                        imgsStr = imgsStr+","+img;
                    }else{
                        imgsStr=img;
                    }
                }
                if (data.length == 0){
                    $pjq.messager.e('内容或图片不能都为空');
                    return;
                }
                obj.goodsInfo = sy.jsonToString(data);
                obj.goodsImgs = imgsStr;
                obj.goodsState = 0;//未出售
                obj.isVerify = 1; //未入库

                //获取标签

                obj.tars=new Array($("#goodsType").combobox('getValues')).join();


                var url=sy.contextPath + '/goods/save';
                $.post(url, obj, function(result) {
                    if (result.code == 0) {
                        $grid.datagrid('reload');
                        $dialog.dialog('destroy');
                    } else {
                        $pjq.messager.e('保存失败,'+result.msg);
                    }
                }, 'json');
            }
        };

        $(function() {
            if (idarr != '') {
                parent.$.messager.progress({
                    text : '数据加载中....'
                });
                $.post(sy.contextPath + '/goods/findByGoods', {
                    idarr : idarr
                }, function (result) {

                    var html = '';
                    for(var i = 0; i< result.length; i++){
                        console.log(result[i].goodsImgs)
                        html += '<tr>';
                        html += '   <th style="width:100px;">商品名称：</th>';
                        html += '<td>';
                        html += '   <input id="goodsName'+i+'" name="goodsName" class="easyui-textbox" missingMessage="请输入" prompt="请输入" style="width:90%;" data-options="required:true" /> ';
                        html += '</td>';
                        html += '    <th style="width:100px;">艺术品组图：</th>';
                        html += '<td>';
                        html += '   <div id="goodsImgs'+i+'" multi="true" fileCountLimit="9" type="file" showImage="true" bestSize="640*320" fileType="jpg,png" showWidth="40" showHeight="40" fileSize="2MB" url="fileUpload"></div>';
                        html += '</td>';
                        html += '</tr>';
                        $('#goodsImgs'+i).setFileId(result[i].goodsImgs,true,1,true);
                        $('#goodsName'+i).textbox('setValue',result[i].goodsName);
                    }

                    $('form').form('load', result);
                    $("#upEth").append(html)
                    parent.$.messager.progress('close');
                });
            }
        });


    </script>
</head>
<body>
<form id="form" method="post">
    <input name="id" type="hidden" />
    <div style="padding:15px;font-size: 12px">
        <table style="table-layout:fixed;" border="0" cellspacing="0" class="formtable" id="upEth">

        </table>
    </div>
</form>
</body>
</html>